//
//  SettingsTableViewController.m
//  Assistant
//
//  Created by liaozhenming on 16/6/6.
//  Copyright © 2016年 liaozhenming. All rights reserved.
//

#import "SettingsTableViewController.h"
#import "CategoryListTableViewController.h"
#import "TransportListTableViewController.h"

#import "KKCellData.h"

@interface SettingsTableViewController ()

@property (nonatomic, strong) NSArray *settingItems;

@end

@implementation SettingsTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"个人中心";
    {
        __weak typeof(self) weakSelf = self;
        KKCellData *categoryItem = [KKCellData new];
        categoryItem.kk_title = @"商品分类";
        categoryItem.kk_eventBlock = ^{
            CategoryListTableViewController *categoryListTableViewController = [CategoryListTableViewController kk_viewControllerFromStoryboard];
            [weakSelf kk_pushViewController: categoryListTableViewController];
        };
        
        KKCellData *transportItem = [KKCellData new];
        transportItem.kk_title = @"物流运输";
        transportItem.kk_eventBlock = ^{
            TransportListTableViewController *listViewController = [TransportListTableViewController kk_viewControllerFromStoryboard];
            [weakSelf kk_pushViewController: listViewController];
        };
        
        _settingItems = @[categoryItem, transportItem];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    if (section == 0) {
        return 1;
    }
    return _settingItems.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return CGFLOAT_MIN;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return CGFLOAT_MIN;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0) {
        return 80;
    }
    return 44.0f;
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0) {
        
        UITableViewCell *cell = [UITableViewCell kk_cellWithTableView: tableView];
        return cell;
    }
    else {
        
        UITableViewCell *cell = [UITableViewCell kk_cellWithTableView: tableView];
        KKCellData *cellItem = _settingItems[indexPath.row];
        cell.textLabel.text = cellItem.kk_title;
        return cell;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0) {
        
        return;
    }
    else {
        KKCellData *cellItem = _settingItems[indexPath.row];
        if (cellItem.kk_eventBlock) {
            cellItem.kk_eventBlock();
        }
    }
}

@end
